<?php

// Global variable for table object
$psacar_car = NULL;

//
// Table class for psacar_car
//
class cpsacar_car {
	var $TableVar = 'psacar_car';
	var $TableName = 'psacar_car';
	var $TableType = 'TABLE';
	var $id;
	var $dealer_id;
	var $external_color_id;
	var $type_id;
	var $category_id;
	var $description;
	var $price;
	var $quality;
	var $post_by;
	var $post_date;
	var $expiration_date;
	var $number_votes;
	var $total_points;
	var $dec_avg;
	var $whole_avg;
	var $internal_color_id;
	var $transmission;
	var $legal;
	var $import_tax;
	var $drive_train;
	var $door_count;
	var $fuel;
	var $vat;
	var $destinations;
	var $rent_type;
	var $vehicle_type_id;
	var $is_driver;
        
	var $image_1;
	var $image_2;
	var $image_3;
	var $image_4;
	var $image_5;

	var $id_image_1;
	var $id_image_2;
	var $id_image_3;
	var $id_image_4;
	var $id_image_5;
        
	var $vehicle_id_number;
	var $negotiate;
	var $duration_type;
	var $duration;
	var $create_date;
	var $end_date;
	var $status;
	var $code;
	var $created_date;
	var $modified_date;
	var $model_id;
	var $year;
	var $fields = array();
	var $UseTokenInUrl = EW_USE_TOKEN_IN_URL;
	var $Export; // Export
	var $ExportOriginalValue = EW_EXPORT_ORIGINAL_VALUE;
	var $ExportAll = TRUE;
	var $SendEmail; // Send email
	var $TableCustomInnerHtml; // Custom inner HTML
	var $BasicSearchKeyword; // Basic search keyword
	var $BasicSearchType; // Basic search type
	var $CurrentFilter; // Current filter
	var $CurrentOrder; // Current order
	var $CurrentOrderType; // Current order type
	var $RowType; // Row type
	var $CssClass; // CSS class
	var $CssStyle; // CSS style
	var $RowAttrs = array(); // Row custom attributes
	var $TableFilter = "";
	var $CurrentAction; // Current action
	var $UpdateConflict; // Update conflict
	var $EventName; // Event name
	var $EventCancelled; // Event cancelled
	var $CancelMessage; // Cancel message

	//
	// Table class constructor
	//
	function cpsacar_car() {
            global $Language;

            // id
            $this->id = new cField('psacar_car', 'psacar_car', 'x_id', 'id', '`id`', 19, -1, FALSE, '`id`', FALSE);
            $this->id->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['id'] =& $this->id;

            // dealer_id
            $this->dealer_id = new cField('psacar_car', 'psacar_car', 'x_dealer_id', 'dealer_id', '`dealer_id`', 19, -1, FALSE, '`dealer_id`', FALSE);
            $this->dealer_id->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['dealer_id'] =& $this->dealer_id;

            // model_id
            $this->model_id = new cField('psacar_car', 'psacar_car', 'x_model_id', 'model_id', '`model_id`', 19, -1, FALSE, '`model_id`', FALSE);
            $this->model_id->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['model_id'] =& $this->model_id;

            // external_color_id
            $this->external_color_id = new cField('psacar_car', 'psacar_car', 'x_external_color_id', 'external_color_id', '`external_color_id`', 3, -1, FALSE, '`external_color_id`', FALSE);
            $this->external_color_id->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['external_color_id'] =& $this->external_color_id;

            // type_id
            $this->type_id = new cField('psacar_car', 'psacar_car', 'x_type_id', 'type_id', '`type_id`', 3, -1, FALSE, '`type_id`', FALSE);
            $this->type_id->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['type_id'] =& $this->type_id;

            // category_id
            $this->category_id = new cField('psacar_car', 'psacar_car', 'x_category_id', 'category_id', '`category_id`', 19, -1, FALSE, '`category_id`', FALSE);
            $this->category_id->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['category_id'] =& $this->category_id;

            // description
            $this->description = new cField('psacar_car', 'psacar_car', 'x_description', 'description', '`description`', 201, -1, FALSE, '`description`', FALSE);
            $this->description->TruncateMemoRemoveHtml = TRUE;
            $this->fields['description'] =& $this->description;

            // price
            $this->price = new cField('psacar_car', 'psacar_car', 'x_price', 'price', '`price`', 5, -1, FALSE, '`price`', FALSE);
            $this->price->FldDefaultErrMsg = $Language->Phrase("IncorrectFloat");
            $this->fields['price'] =& $this->price;

            // quality
            $this->quality = new cField('psacar_car', 'psacar_car', 'x_quality', 'quality', '`quality`', 3, -1, FALSE, '`quality`', FALSE);
            $this->quality->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['quality'] =& $this->quality;

            // post_by
            $this->post_by = new cField('psacar_car', 'psacar_car', 'x_post_by', 'post_by', '`post_by`', 3, -1, FALSE, '`post_by`', FALSE);
            $this->post_by->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['post_by'] =& $this->post_by;

            // post_date
            $this->post_date = new cField('psacar_car', 'psacar_car', 'x_post_date', 'post_date', '`post_date`', 133, 5, FALSE, '`post_date`', FALSE);
            $this->post_date->FldDefaultErrMsg = str_replace("%s", "/", $Language->Phrase("IncorrectDateYMD"));
            $this->fields['post_date'] =& $this->post_date;

            // expiration_date
            $this->expiration_date = new cField('psacar_car', 'psacar_car', 'x_expiration_date', 'expiration_date', '`expiration_date`', 133, 5, FALSE, '`expiration_date`', FALSE);
            $this->expiration_date->FldDefaultErrMsg = str_replace("%s", "/", $Language->Phrase("IncorrectDateYMD"));
            $this->fields['expiration_date'] =& $this->expiration_date;

            // number_votes
            $this->number_votes = new cField('psacar_car', 'psacar_car', 'x_number_votes', 'number_votes', '`number_votes`', 3, -1, FALSE, '`number_votes`', FALSE);
            $this->number_votes->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['number_votes'] =& $this->number_votes;

            // total_points
            $this->total_points = new cField('psacar_car', 'psacar_car', 'x_total_points', 'total_points', '`total_points`', 3, -1, FALSE, '`total_points`', FALSE);
            $this->total_points->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['total_points'] =& $this->total_points;

            // dec_avg
            $this->dec_avg = new cField('psacar_car', 'psacar_car', 'x_dec_avg', 'dec_avg', '`dec_avg`', 5, -1, FALSE, '`dec_avg`', FALSE);
            $this->dec_avg->FldDefaultErrMsg = $Language->Phrase("IncorrectFloat");
            $this->fields['dec_avg'] =& $this->dec_avg;

            // whole_avg
            $this->whole_avg = new cField('psacar_car', 'psacar_car', 'x_whole_avg', 'whole_avg', '`whole_avg`', 5, -1, FALSE, '`whole_avg`', FALSE);
            $this->whole_avg->FldDefaultErrMsg = $Language->Phrase("IncorrectFloat");
            $this->fields['whole_avg'] =& $this->whole_avg;

            // internal_color_id
            $this->internal_color_id = new cField('psacar_car', 'psacar_car', 'x_internal_color_id', 'internal_color_id', '`internal_color_id`', 3, -1, FALSE, '`internal_color_id`', FALSE);
            $this->internal_color_id->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['internal_color_id'] =& $this->internal_color_id;

            // transmission
            $this->transmission = new cField('psacar_car', 'psacar_car', 'x_transmission', 'transmission', '`transmission`', 3, -1, FALSE, '`transmission`', FALSE);
            $this->transmission->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['transmission'] =& $this->transmission;

            // legal
            $this->legal = new cField('psacar_car', 'psacar_car', 'x_legal', 'legal', '`legal`', 3, -1, FALSE, '`legal`', FALSE);
            $this->legal->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['legal'] =& $this->legal;

            // import_tax
            $this->import_tax = new cField('psacar_car', 'psacar_car', 'x_import_tax', 'import_tax', '`import_tax`', 3, -1, FALSE, '`import_tax`', FALSE);
            $this->import_tax->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['import_tax'] =& $this->import_tax;

            // drive_train
            $this->drive_train = new cField('psacar_car', 'psacar_car', 'x_drive_train', 'drive_train', '`drive_train`', 3, -1, FALSE, '`drive_train`', FALSE);
            $this->drive_train->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['drive_train'] =& $this->drive_train;

            // door_count
            $this->door_count = new cField('psacar_car', 'psacar_car', 'x_door_count', 'door_count', '`door_count`', 3, -1, FALSE, '`door_count`', FALSE);
            $this->door_count->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['door_count'] =& $this->door_count;

            // fuel
            $this->fuel = new cField('psacar_car', 'psacar_car', 'x_fuel', 'fuel', '`fuel`', 200, -1, FALSE, '`fuel`', FALSE);
            $this->fuel->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['fuel'] =& $this->fuel;

            // vat
            $this->vat = new cField('psacar_car', 'psacar_car', 'x_vat', 'vat', '`vat`', 3, -1, FALSE, '`vat`', FALSE);
            $this->vat->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['vat'] =& $this->vat;

            // destinations
            $this->destinations = new cField('psacar_car', 'psacar_car', 'x_destinations', 'destinations', '`destinations`', 3, -1, FALSE, '`destinations`', FALSE);
            $this->destinations->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['destinations'] =& $this->destinations;

            // rent_type
            $this->rent_type = new cField('psacar_car', 'psacar_car', 'x_rent_type', 'rent_type', '`rent_type`', 3, -1, FALSE, '`rent_type`', FALSE);
            $this->rent_type->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['rent_type'] =& $this->rent_type;

            // vehicle_type_id
            $this->vehicle_type_id = new cField('psacar_car', 'psacar_car', 'x_vehicle_type_id', 'vehicle_type_id', '`vehicle_type_id`', 3, -1, FALSE, '`vehicle_type_id`', FALSE);
            $this->vehicle_type_id->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['vehicle_type_id'] =& $this->vehicle_type_id;

            // is_driver
            $this->is_driver = new cField('psacar_car', 'psacar_car', 'x_is_driver', 'is_driver', '`is_driver`', 3, -1, FALSE, '`is_driver`', FALSE);
            $this->is_driver->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['is_driver'] =& $this->is_driver;

            // image_1
            $this->image_1 = new cField('psacar_car', 'psacar_car', 'x_image_1', 'image_1', '`image`', 200, -1, TRUE, '`image`', FALSE);
            $this->image_1->UploadPath = "../system/public/assets/cars/";
            $this->fields['image_1'] =& $this->image_1;

            // image_2
            $this->image_2 = new cField('psacar_car', 'psacar_car', 'x_image_2', 'image_2', '`image`', 200, -1, TRUE, '`image`', FALSE);
            $this->image_2->UploadPath = "../system/public/assets/cars/";
            $this->fields['image_2'] =& $this->image_2;

            // image_3
            $this->image_3 = new cField('psacar_car', 'psacar_car', 'x_image_3', 'image_3', '`image`', 200, -1, TRUE, '`image`', FALSE);
            $this->image_3->UploadPath = "../system/public/assets/cars/";
            $this->fields['image_3'] =& $this->image_3;

            // image_4
            $this->image_4 = new cField('psacar_car', 'psacar_car', 'x_image_4', 'image_4', '`image`', 200, -1, TRUE, '`image`', FALSE);
            $this->image_4->UploadPath = "../system/public/assets/cars/";
            $this->fields['image_4'] =& $this->image_4;

            // image_5
            $this->image_5 = new cField('psacar_car', 'psacar_car', 'x_image_5', 'image_5', '`image`', 200, -1, TRUE, '`image`', FALSE);
            $this->image_5->UploadPath = "../system/public/assets/cars/";
            $this->fields['image_5'] =& $this->image_5;

            // id_image_1
            $this->id_image_1 = new cField('psacar_car', 'psacar_car', 'id_image_1', 'id_image_1', '`id_image_1`', 19, -1, FALSE, '`id_image_1`', FALSE);
            $this->id_image_1->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['id_image_1'] =& $this->id_image_1;
            
            // id_image_2
            $this->id_image_2 = new cField('psacar_car', 'psacar_car', 'id_image_2', 'id_image_2', '`id_image_2`', 19, -1, FALSE, '`id_image_2`', FALSE);
            $this->id_image_2->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['id_image_2'] =& $this->id_image_1;
            
            // id_image_3
            $this->id_image_3 = new cField('psacar_car', 'psacar_car', 'id_image_3', 'id_image_3', '`id_image_3`', 19, -1, FALSE, '`id_image_3`', FALSE);
            $this->id_image_3->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['id_image_3'] =& $this->id_image_3;
            
            // id_image_4
            $this->id_image_4 = new cField('psacar_car', 'psacar_car', 'id_image_4', 'id_image_4', '`id_image_4`', 19, -1, FALSE, '`id_image_4`', FALSE);
            $this->id_image_4->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['id_image_4'] =& $this->id_image_4;
            
            // id_image_5
            $this->id_image_5 = new cField('psacar_car', 'psacar_car', 'id_image_5', 'id_image_5', '`id_image_5`', 19, -1, FALSE, '`id_image_5`', FALSE);
            $this->id_image_5->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['id_image_5'] =& $this->id_image_5;
            
            // vehicle_id_number
            $this->vehicle_id_number = new cField('psacar_car', 'psacar_car', 'x_vehicle_id_number', 'vehicle_id_number', '`vehicle_id_number`', 200, -1, FALSE, '`vehicle_id_number`', FALSE);
            $this->fields['vehicle_id_number'] =& $this->vehicle_id_number;

            // negotiate
            $this->negotiate = new cField('psacar_car', 'psacar_car', 'x_negotiate', 'negotiate', '`negotiate`', 3, -1, FALSE, '`negotiate`', FALSE);
            $this->negotiate->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['negotiate'] =& $this->negotiate;

            // duration_type
            $this->duration_type = new cField('psacar_car', 'psacar_car', 'x_duration_type', 'duration_type', '`duration_type`', 3, -1, FALSE, '`duration_type`', FALSE);
            $this->duration_type->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['duration_type'] =& $this->duration_type;

            // duration
            $this->duration = new cField('psacar_car', 'psacar_car', 'x_duration', 'duration', '`duration`', 3, -1, FALSE, '`duration`', FALSE);
            $this->duration->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['duration'] =& $this->duration;

            // create_date
            $this->create_date = new cField('psacar_car', 'psacar_car', 'x_create_date', 'create_date', '`create_date`', 133, 5, FALSE, '`create_date`', FALSE);
            $this->create_date->FldDefaultErrMsg = str_replace("%s", "/", $Language->Phrase("IncorrectDateYMD"));
            $this->fields['create_date'] =& $this->create_date;

            // end_date
            $this->end_date = new cField('psacar_car', 'psacar_car', 'x_end_date', 'end_date', '`end_date`', 133, 5, FALSE, '`end_date`', FALSE);
            $this->end_date->FldDefaultErrMsg = str_replace("%s", "/", $Language->Phrase("IncorrectDateYMD"));
            $this->fields['end_date'] =& $this->end_date;

            // status
            $this->status = new cField('psacar_car', 'psacar_car', 'x_status', 'status', '`status`', 3, -1, FALSE, '`status`', FALSE);
            $this->status->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['status'] =& $this->status;

            // code
            $this->code = new cField('psacar_car', 'psacar_car', 'x_code', 'code', '`code`', 200, -1, FALSE, '`code`', FALSE);
            $this->fields['code'] =& $this->code;

            // created_date
            $this->created_date = new cField('psacar_car', 'psacar_car', 'x_created_date', 'created_date', '`created_date`', 133, 5, FALSE, '`created_date`', FALSE);
            $this->created_date->FldDefaultErrMsg = str_replace("%s", "/", $Language->Phrase("IncorrectDateYMD"));
            $this->fields['created_date'] =& $this->created_date;

            // modified_date
            $this->modified_date = new cField('psacar_car', 'psacar_car', 'x_modified_date', 'modified_date', '`modified_date`', 133, 5, FALSE, '`modified_date`', FALSE);
            $this->modified_date->FldDefaultErrMsg = str_replace("%s", "/", $Language->Phrase("IncorrectDateYMD"));
            $this->fields['modified_date'] =& $this->modified_date;

            // model_id
            $this->model_id = new cField('psacar_car', 'psacar_car', 'x_model_id', 'model_id', '`model_id`', 19, -1, FALSE, '`model_id`', FALSE);
            $this->model_id->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['model_id'] =& $this->model_id;

            // year
            $this->year = new cField('psacar_car', 'psacar_car', 'x_year', 'year', '`year`', 19, -1, FALSE, '`year`', FALSE);
            $this->year->FldDefaultErrMsg = $Language->Phrase("IncorrectInteger");
            $this->fields['year'] =& $this->year;                
	}

	// Table caption
	function TableCaption() {
            global $Language;
            return $Language->TablePhrase($this->TableVar, "TblCaption");
	}

	// Page caption
	function PageCaption($Page) {
            global $Language;
            $Caption = $Language->TablePhrase($this->TableVar, "TblPageCaption" . $Page);
            if ($Caption == "") $Caption = "Page " . $Page;
            return $Caption;
	}

	// Export return page
	function ExportReturnUrl() {
		$url = @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_EXPORT_RETURN_URL];
		return ($url <> "") ? $url : ew_CurrentPage();
	}

	function setExportReturnUrl($v) {
		$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_EXPORT_RETURN_URL] = $v;
	}

	// Records per page
	function getRecordsPerPage() {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_REC_PER_PAGE];
	}

	function setRecordsPerPage($v) {
		$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_REC_PER_PAGE] = $v;
	}

	// Start record number
	function getStartRecordNumber() {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_START_REC];
	}

	function setStartRecordNumber($v) {
		$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_START_REC] = $v;
	}

	// Search highlight name
	function HighlightName() {
		return "psacar_car_Highlight";
	}

	// Advanced search
	function getAdvancedSearch($fld) {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_ADVANCED_SEARCH . "_" . $fld];
	}

	function setAdvancedSearch($fld, $v) {
		if (@$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_ADVANCED_SEARCH . "_" . $fld] <> $v) {
			$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_ADVANCED_SEARCH . "_" . $fld] = $v;
		}
	}

	// Basic search keyword
	function getSessionBasicSearchKeyword() {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_BASIC_SEARCH];
	}

	function setSessionBasicSearchKeyword($v) {
		$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_BASIC_SEARCH] = $v;
	}

	// Basic search type
	function getSessionBasicSearchType() {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_BASIC_SEARCH_TYPE];
	}

	function setSessionBasicSearchType($v) {
		$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_BASIC_SEARCH_TYPE] = $v;
	}

	// Search WHERE clause
	function getSearchWhere() {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_SEARCH_WHERE];
	}

	function setSearchWhere($v) {
		$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_SEARCH_WHERE] = $v;
	}

	// Single column sort
	function UpdateSort(&$ofld) {
		if ($this->CurrentOrder == $ofld->FldName) {
			$sSortField = $ofld->FldExpression;
			$sLastSort = $ofld->getSort();
			if ($this->CurrentOrderType == "ASC" || $this->CurrentOrderType == "DESC") {
				$sThisSort = $this->CurrentOrderType;
			} else {
				$sThisSort = ($sLastSort == "ASC") ? "DESC" : "ASC";
			}
			$ofld->setSort($sThisSort);
			$this->setSessionOrderBy($sSortField . " " . $sThisSort); // Save to Session
		} else {
			$ofld->setSort("");
		}
	}

	// Session WHERE clause
	function getSessionWhere() {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_WHERE];
	}

	function setSessionWhere($v) {
		$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_WHERE] = $v;
	}

	// Session ORDER BY
	function getSessionOrderBy() {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_ORDER_BY];
	}

	function setSessionOrderBy($v) {
		$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_ORDER_BY] = $v;
	}

	// Session key
	function getKey($fld) {
		return @$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_KEY . "_" . $fld];
	}

	function setKey($fld, $v) {
		$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_KEY . "_" . $fld] = $v;
	}

	// Table level SQL
	function SqlFrom() { // From
		return "`psacar_car`";
	}

	function SqlSelect() { // Select
		return "SELECT * FROM " . $this->SqlFrom();
	}

	function SqlWhere() { // Where
		$sWhere = "";
		$this->TableFilter = "";
		if ($this->TableFilter <> "") {
			if ($sWhere <> "") $sWhere .= "(" . $sWhere . ") AND (";
			$sWhere .= "(" . $this->TableFilter . ")";
		}
		return $sWhere;
	}

	function SqlGroupBy() { // Group By
		return "";
	}

	function SqlHaving() { // Having
		return "";
	}

	function SqlOrderBy() { // Order By
		return "";
	}

	// Check if Anonymous User is allowed
	function AllowAnonymousUser() {
		switch (EW_PAGE_ID) {
			case "add":
			case "register":
			case "addopt":
				return FALSE;
			case "edit":
			case "update":
				return FALSE;
			case "delete":
				return FALSE;
			case "view":
				return FALSE;
			case "search":
				return FALSE;
			default:
				return FALSE;
		}
	}

	// Apply User ID filters
	function ApplyUserIDFilters($sFilter) {
		return $sFilter;
	}

	// Get SQL
	function GetSQL($where, $orderby) {
		return ew_BuildSelectSql($this->SqlSelect(), $this->SqlWhere(),
			$this->SqlGroupBy(), $this->SqlHaving(), $this->SqlOrderBy(),
			$where, $orderby);
	}

	// Table SQL
	function SQL() {
		$sFilter = $this->CurrentFilter;
		$sFilter = $this->ApplyUserIDFilters($sFilter);
		$sSort = $this->getSessionOrderBy();
		return ew_BuildSelectSql($this->SqlSelect(), $this->SqlWhere(),
			$this->SqlGroupBy(), $this->SqlHaving(), $this->SqlOrderBy(),
			$sFilter, $sSort);
	}

	// Table SQL with List page filter
	function SelectSQL() {
            $sFilter = $this->getSessionWhere();
            if ($this->CurrentFilter <> "") {
                if ($sFilter <> "") $sFilter = "(" . $sFilter . ") AND ";
                $sFilter .= "(" . $this->CurrentFilter . ")";
            }
            $sFilter = $this->ApplyUserIDFilters($sFilter);
            $sSort = $this->getSessionOrderBy();
            return ew_BuildSelectSql($this->SqlSelect(), $this->SqlWhere(), $this->SqlGroupBy(),
                $this->SqlHaving(), $this->SqlOrderBy(), $sFilter, $sSort);
	}

	// Try to get record count
	function TryGetRecordCount($sSql) {
		global $conn;
		$cnt = -1;
		if ($this->TableType == 'TABLE' || $this->TableType == 'VIEW') {
			$sSql = "SELECT COUNT(*) FROM" . substr($sSql, 13);
		} else {
			$sSql = "SELECT COUNT(*) FROM (" . $sSql . ") EW_COUNT_TABLE";
		}
		if ($rs = $conn->Execute($sSql)) {
			if (!$rs->EOF && $rs->FieldCount() > 0) {
				$cnt = $rs->fields[0];
				$rs->Close();
			}
		}
		return intval($cnt);
	}

	// Get record count based on filter (for detail record count in master table pages)
	function LoadRecordCount($sFilter) {
		$origFilter = $this->CurrentFilter;
		$this->CurrentFilter = $sFilter;
		$this->Recordset_Selecting($this->CurrentFilter);
		$sSql = $this->SQL();
		$cnt = $this->TryGetRecordCount($sSql);
		if ($cnt == -1) {
			if ($rs = $this->LoadRs($this->CurrentFilter)) {
				$cnt = $rs->RecordCount();
				$rs->Close();
			}
		}
		$this->CurrentFilter = $origFilter;
		return intval($cnt);
	}

	// Get record count (for current List page)
	function SelectRecordCount() {
		global $conn;
		$origFilter = $this->CurrentFilter;
		$this->Recordset_Selecting($this->CurrentFilter);
		$sSql = $this->SelectSQL();
		$cnt = $this->TryGetRecordCount($sSql);
		if ($cnt == -1) {
			if ($rs = $conn->Execute($this->SelectSQL())) {
				$cnt = $rs->RecordCount();
				$rs->Close();
			}
		}
		$this->CurrentFilter = $origFilter;
		return intval($cnt);
	}

	// INSERT statement
	function InsertSQL(&$rs) {
		global $conn;
		$names = "";
		$values = "";
		foreach ($rs as $name => $value) {
			$names .= $this->fields[$name]->FldExpression . ",";
			$values .= ew_QuotedValue($value, $this->fields[$name]->FldDataType) . ",";
		}
		if (substr($names, -1) == ",") $names = substr($names, 0, strlen($names)-1);
		if (substr($values, -1) == ",") $values = substr($values, 0, strlen($values)-1);
		return "INSERT INTO `psacar_car` ($names) VALUES ($values)";
	}

	// UPDATE statement
	function UpdateSQL(&$rs) {
		global $conn;
		$SQL = "UPDATE `psacar_car` SET ";
		foreach ($rs as $name => $value) {
			$SQL .= $this->fields[$name]->FldExpression . "=";
			$SQL .= ew_QuotedValue($value, $this->fields[$name]->FldDataType) . ",";
		}
		if (substr($SQL, -1) == ",") $SQL = substr($SQL, 0, strlen($SQL)-1);
		if ($this->CurrentFilter <> "")	$SQL .= " WHERE " . $this->CurrentFilter;
		return $SQL;
	}

	// DELETE statement
	function DeleteSQL(&$rs) {
		$SQL = "DELETE FROM `psacar_car` WHERE ";
		$SQL .= ew_QuotedName('id') . '=' . ew_QuotedValue($rs['id'], $this->id->FldDataType) . ' AND ';
		if (substr($SQL, -5) == " AND ") $SQL = substr($SQL, 0, strlen($SQL)-5);
		if ($this->CurrentFilter <> "")	$SQL .= " AND " . $this->CurrentFilter;
		return $SQL;
	}

	// Key filter WHERE clause
	function SqlKeyFilter() {
            return "`id` = @id@";
	}

	// Key filter
	function KeyFilter() {
            $sKeyFilter = $this->SqlKeyFilter();
            if (!is_numeric($this->id->CurrentValue))
                $sKeyFilter = "0=1"; // Invalid key
            $sKeyFilter = str_replace("@id@", ew_AdjustSql($this->id->CurrentValue), $sKeyFilter); // Replace key value
            return $sKeyFilter;
	}

	// Return page URL
	function getReturnUrl() {
		$name = EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_RETURN_URL;

		// Get referer URL automatically
		if (ew_ServerVar("HTTP_REFERER") <> "" && ew_ReferPage() <> ew_CurrentPage() && ew_ReferPage() <> "login.php") // Referer not same page or login page
			$_SESSION[$name] = ew_ServerVar("HTTP_REFERER"); // Save to Session
		if (@$_SESSION[$name] <> "") {
			return $_SESSION[$name];
		} else {
			return "psacar_carlist.php";
		}
	}

	function setReturnUrl($v) {
		$_SESSION[EW_PROJECT_NAME . "_" . $this->TableVar . "_" . EW_TABLE_RETURN_URL] = $v;
	}

	// List URL
	function ListUrl() {
		return "psacar_carlist.php";
	}

	// View URL
	function ViewUrl() {
		return $this->KeyUrl("psacar_carview.php", $this->UrlParm());
	}

	// Add URL
	function AddUrl() {
		$AddUrl = "psacar_caradd.php";
		$sUrlParm = $this->UrlParm();
		if ($sUrlParm <> "")
			$AddUrl .= "?" . $sUrlParm;
		return $AddUrl;
	}

	// Edit URL
	function EditUrl() {
		return $this->KeyUrl("psacar_caredit.php", $this->UrlParm());
	}

	// Inline edit URL
	function InlineEditUrl() {
		return $this->KeyUrl(ew_CurrentPage(), $this->UrlParm("a=edit"));
	}

	// Copy URL
	function CopyUrl() {
		return $this->KeyUrl("psacar_caradd.php", $this->UrlParm());
	}

	// Inline copy URL
	function InlineCopyUrl() {
		return $this->KeyUrl(ew_CurrentPage(), $this->UrlParm("a=copy"));
	}

	// Delete URL
	function DeleteUrl() {
		return $this->KeyUrl("psacar_cardelete.php", $this->UrlParm());
	}

	// Add key value to URL
	function KeyUrl($url, $parm = "") {
		$sUrl = $url . "?";
		if ($parm <> "") $sUrl .= $parm . "&";
		if (!is_null($this->id->CurrentValue)) {
			$sUrl .= "id=" . urlencode($this->id->CurrentValue);
		} else {
			return "javascript:alert(ewLanguage.Phrase(\"InvalidRecord\"));";
		}
		return $sUrl;
	}

	// Sort URL
	function SortUrl(&$fld) {
		if ($this->CurrentAction <> "" || $this->Export <> "" ||
			in_array($fld->FldType, array(128, 204, 205))) { // Unsortable data type
				return "";
		} elseif ($fld->Sortable) {
			$sUrlParm = $this->UrlParm("order=" . urlencode($fld->FldName) . "&ordertype=" . $fld->ReverseSort());
			return ew_CurrentPage() . "?" . $sUrlParm;
		} else {
			return "";
		}
	}

	// Add URL parameter
	function UrlParm($parm = "") {
		$UrlParm = ($this->UseTokenInUrl) ? "t=psacar_car" : "";
		if ($parm <> "") {
			if ($UrlParm <> "")
				$UrlParm .= "&";
			$UrlParm .= $parm;
		}
		return $UrlParm;
	}

	// Load rows based on filter
	function &LoadRs($sFilter) {
		global $conn;

		// Set up filter (SQL WHERE clause) and get return SQL
		$this->CurrentFilter = $sFilter;
		$sSql = $this->SQL();
		return $conn->Execute($sSql);
	}

	// Load row values from recordset
	function LoadListRowValues(&$rs) {
            $this->id->setDbValue($rs->fields('id'));
            $this->dealer_id->setDbValue($rs->fields('dealer_id'));
            //$this->model_id->setDbValue($rs->fields('model_id'));
            $this->external_color_id->setDbValue($rs->fields('external_color_id'));
            $this->type_id->setDbValue($rs->fields('type_id'));
            $this->category_id->setDbValue($rs->fields('category_id'));
            $this->description->setDbValue($rs->fields('description'));
            $this->price->setDbValue($rs->fields('price'));
            $this->quality->setDbValue($rs->fields('quality'));
            $this->post_by->setDbValue($rs->fields('post_by'));
            $this->post_date->setDbValue($rs->fields('post_date'));
            $this->expiration_date->setDbValue($rs->fields('expiration_date'));
            $this->number_votes->setDbValue($rs->fields('number_votes'));
            $this->total_points->setDbValue($rs->fields('total_points'));
            $this->dec_avg->setDbValue($rs->fields('dec_avg'));
            $this->whole_avg->setDbValue($rs->fields('whole_avg'));
            $this->internal_color_id->setDbValue($rs->fields('internal_color_id'));
            $this->transmission->setDbValue($rs->fields('transmission'));
            $this->legal->setDbValue($rs->fields('legal'));
            $this->import_tax->setDbValue($rs->fields('import_tax'));
            $this->drive_train->setDbValue($rs->fields('drive_train'));
            $this->door_count->setDbValue($rs->fields('door_count'));
            $this->fuel->setDbValue($rs->fields('fuel'));
            $this->vat->setDbValue($rs->fields('vat'));
            $this->destinations->setDbValue($rs->fields('destinations'));
            $this->rent_type->setDbValue($rs->fields('rent_type'));
            $this->vehicle_type_id->setDbValue($rs->fields('vehicle_type_id'));
            $this->is_driver->setDbValue($rs->fields('is_driver'));

            $this->image_1->Upload->DbValue = $rs->fields('image_1');
            $this->image_2->Upload->DbValue = $rs->fields('image_2');
            $this->image_3->Upload->DbValue = $rs->fields('image_3');
            $this->image_4->Upload->DbValue = $rs->fields('image_4');
            $this->image_5->Upload->DbValue = $rs->fields('image_5');

            $this->id_image_1->setDbValue($rs->fields('id_image_1'));
            $this->id_image_2->setDbValue($rs->fields('id_image_2'));
            $this->id_image_3->setDbValue($rs->fields('id_image_3'));
            $this->id_image_4->setDbValue($rs->fields('id_image_4'));
            $this->id_image_5->setDbValue($rs->fields('id_image_5'));

            $this->vehicle_id_number->setDbValue($rs->fields('vehicle_id_number'));
            $this->negotiate->setDbValue($rs->fields('negotiate'));
            $this->duration_type->setDbValue($rs->fields('duration_type'));
            $this->duration->setDbValue($rs->fields('duration'));
            $this->create_date->setDbValue($rs->fields('create_date'));
            $this->end_date->setDbValue($rs->fields('end_date'));
            $this->status->setDbValue($rs->fields('status'));
            $this->code->setDbValue($rs->fields('code'));
            $this->created_date->setDbValue($rs->fields('created_date'));
            $this->modified_date->setDbValue($rs->fields('modified_date'));
            $this->model_id->setDbValue($rs->fields('model_id'));
            $this->year->setDbValue($rs->fields('year'));
	}

	// Render list row values
	function RenderListRow() {
            global $conn, $Security;

            // Call Row Rendering event
            $this->Row_Rendering();

            // Common render codes
            // id

            $this->id->CellCssStyle = ""; $this->id->CellCssClass = "";
            $this->id->CellAttrs = array(); $this->id->ViewAttrs = array(); $this->id->EditAttrs = array();

            // dealer_id
            $this->dealer_id->CellCssStyle = ""; $this->dealer_id->CellCssClass = "";
            $this->dealer_id->CellAttrs = array(); $this->dealer_id->ViewAttrs = array(); $this->dealer_id->EditAttrs = array();

            // model_id
            $this->model_id->CellCssStyle = ""; $this->model_id->CellCssClass = "";
            $this->model_id->CellAttrs = array(); $this->model_id->ViewAttrs = array(); $this->model_id->EditAttrs = array();

            // type_id
            $this->type_id->CellCssStyle = ""; $this->type_id->CellCssClass = "";
            $this->type_id->CellAttrs = array(); $this->type_id->ViewAttrs = array(); $this->type_id->EditAttrs = array();

            // category_id
            $this->category_id->CellCssStyle = ""; $this->category_id->CellCssClass = "";
            $this->category_id->CellAttrs = array(); $this->category_id->ViewAttrs = array(); $this->category_id->EditAttrs = array();

            // price
            $this->price->CellCssStyle = ""; $this->price->CellCssClass = "";
            $this->price->CellAttrs = array(); $this->price->ViewAttrs = array(); $this->price->EditAttrs = array();

            // quality
            $this->quality->CellCssStyle = "white-space: nowrap;"; $this->quality->CellCssClass = "";
            $this->quality->CellAttrs = array(); $this->quality->ViewAttrs = array(); $this->quality->EditAttrs = array();

            // fuel
            $this->fuel->CellCssStyle = ""; $this->fuel->CellCssClass = "";
            $this->fuel->CellAttrs = array(); $this->fuel->ViewAttrs = array(); $this->fuel->EditAttrs = array();

            // rent_type
            $this->rent_type->CellCssStyle = ""; $this->rent_type->CellCssClass = "";
            $this->rent_type->CellAttrs = array(); $this->rent_type->ViewAttrs = array(); $this->rent_type->EditAttrs = array();

            // vehicle_type_id
            $this->vehicle_type_id->CellCssStyle = ""; $this->vehicle_type_id->CellCssClass = "";
            $this->vehicle_type_id->CellAttrs = array(); $this->vehicle_type_id->ViewAttrs = array(); $this->vehicle_type_id->EditAttrs = array();

            // model_id
            $this->model_id->CellCssStyle = ""; $this->model_id->CellCssClass = "";
            $this->model_id->CellAttrs = array(); $this->model_id->ViewAttrs = array(); $this->model_id->EditAttrs = array();

            // year
            $this->year->CellCssStyle = ""; $this->year->CellCssClass = "";
            $this->year->CellAttrs = array(); $this->year->ViewAttrs = array(); $this->year->EditAttrs = array();

            // id
            $this->id->ViewValue = $this->id->CurrentValue;
            $this->id->CssStyle = "";
            $this->id->CssClass = "";
            $this->id->ViewCustomAttributes = "";

            // dealer_id
            if (strval($this->dealer_id->CurrentValue) <> "") {
                $sFilterWrk = "`id` = " . ew_AdjustSql($this->dealer_id->CurrentValue) . "";
            $sSqlWrk = "SELECT `name` FROM `psacar_member`";
            $sWhereWrk = "";
            if ($sFilterWrk <> "") {
                    if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
                    $sWhereWrk .= "(" . $sFilterWrk . ")";
            }
            if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
                    $rswrk = $conn->Execute($sSqlWrk);
                    if ($rswrk && !$rswrk->EOF) { // Lookup values found
                            $this->dealer_id->ViewValue = $rswrk->fields('name');
                            $rswrk->Close();
                    } else {
                            $this->dealer_id->ViewValue = $this->dealer_id->CurrentValue;
                    }
            } else {
                    $this->dealer_id->ViewValue = NULL;
            }
            $this->dealer_id->CssStyle = "";
            $this->dealer_id->CssClass = "";
            $this->dealer_id->ViewCustomAttributes = "";

            // model_id
            if (strval($this->model_id->CurrentValue) <> "") {
                $sFilterWrk = "id = " . ew_AdjustSql($this->model_id->CurrentValue) . "";
                $sSqlWrk = "SELECT `name` FROM psacar_model";
                $sWhereWrk = "";

                if ($sFilterWrk <> "") {
                    if ($sWhereWrk <> "") 
                        $sWhereWrk .= " AND ";
                    $sWhereWrk .= "(" . $sFilterWrk . ")";
                }

                if ($sWhereWrk <> "") 
                    $sSqlWrk .= " WHERE " . $sWhereWrk;

                $rswrk = $conn->Execute($sSqlWrk);
                if ($rswrk && !$rswrk->EOF) { // Lookup values found
                    $this->model_id->ViewValue = $rswrk->fields('name');
                    $rswrk->Close();
                } 
                else {
                    $this->model_id->ViewValue = $this->model_id->CurrentValue;
                }
            } 
            else {
                $this->model_id->ViewValue = NULL;
            }

            $this->model_id->CssStyle = "";
            $this->model_id->CssClass = "";
            $this->model_id->ViewCustomAttributes = "";

            // type_id
            if (strval($this->type_id->CurrentValue) <> "") {
                    $sFilterWrk = "`id` = " . ew_AdjustSql($this->type_id->CurrentValue) . "";
            $sSqlWrk = "SELECT `name` FROM `psacar_car_type`";
            $sWhereWrk = "";
            if ($sFilterWrk <> "") {
                    if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
                    $sWhereWrk .= "(" . $sFilterWrk . ")";
            }
            if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
                    $rswrk = $conn->Execute($sSqlWrk);
                    if ($rswrk && !$rswrk->EOF) { // Lookup values found
                            $this->type_id->ViewValue = $rswrk->fields('name');
                            $rswrk->Close();
                    } else {
                            $this->type_id->ViewValue = $this->type_id->CurrentValue;
                    }
            } else {
                    $this->type_id->ViewValue = NULL;
            }
            $this->type_id->CssStyle = "";
            $this->type_id->CssClass = "";
            $this->type_id->ViewCustomAttributes = "";

            // category_id
            if (strval($this->category_id->CurrentValue) <> "") {
                    $sFilterWrk = "`category_id` = " . ew_AdjustSql($this->category_id->CurrentValue) . "";
            $sSqlWrk = "SELECT `category_name` FROM `psacar_category`";
            $sWhereWrk = "";
            if ($sFilterWrk <> "") {
                    if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
                    $sWhereWrk .= "(" . $sFilterWrk . ")";
            }
            if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
                    $rswrk = $conn->Execute($sSqlWrk);
                    if ($rswrk && !$rswrk->EOF) { // Lookup values found
                            $this->category_id->ViewValue = $rswrk->fields('category_name');
                            $rswrk->Close();
                    } else {
                            $this->category_id->ViewValue = $this->category_id->CurrentValue;
                    }
            } else {
                    $this->category_id->ViewValue = NULL;
            }
            $this->category_id->CssStyle = "";
            $this->category_id->CssClass = "";
            $this->category_id->ViewCustomAttributes = "";

            // price
            $this->price->ViewValue = $this->price->CurrentValue;
            $this->price->CssStyle = "";
            $this->price->CssClass = "";
            $this->price->ViewCustomAttributes = "";

            // quality
            $this->quality->ViewValue = $this->quality->CurrentValue;
            if (strval($this->quality->CurrentValue) <> "") {
                    $sFilterWrk = "`code` = " . ew_AdjustSql($this->quality->CurrentValue) . "";
            $sSqlWrk = "SELECT `mileage` FROM `psacar_mileage`";
            $sWhereWrk = "";
            if ($sFilterWrk <> "") {
                    if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
                    $sWhereWrk .= "(" . $sFilterWrk . ")";
            }
            if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
                    $rswrk = $conn->Execute($sSqlWrk);
                    if ($rswrk && !$rswrk->EOF) { // Lookup values found
                            $this->quality->ViewValue = $rswrk->fields('mileage');
                            $rswrk->Close();
                    } else {
                            $this->quality->ViewValue = $this->quality->CurrentValue;
                    }
            } else {
                    $this->quality->ViewValue = NULL;
            }
            $this->quality->CssStyle = "";
            $this->quality->CssClass = "";
            $this->quality->ViewCustomAttributes = "";

            // fuel
            if (strval($this->fuel->CurrentValue) <> "") {
                    $arwrk = explode(",", $this->fuel->CurrentValue);
                    $sFilterWrk = "";
                    foreach ($arwrk as $wrk) {
                            if ($sFilterWrk <> "") $sFilterWrk .= " OR ";
                            $sFilterWrk .= "`id` = " . ew_AdjustSql(trim($wrk)) . "";
                    }	
            $sSqlWrk = "SELECT `fuel` FROM `psacar_fuel`";
            $sWhereWrk = "";
            if ($sFilterWrk <> "") {
                    if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
                    $sWhereWrk .= "(" . $sFilterWrk . ")";
            }
            if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
                    $rswrk = $conn->Execute($sSqlWrk);
                    if ($rswrk && !$rswrk->EOF) { // Lookup values found
                            $this->fuel->ViewValue = "";
                            $ari = 0;
                            while (!$rswrk->EOF) {
                                    $this->fuel->ViewValue .= $rswrk->fields('fuel');
                                    $rswrk->MoveNext();
                                    if (!$rswrk->EOF) $this->fuel->ViewValue .= ew_ViewOptionSeparator($ari); // Separate Options
                                    $ari++;
                            }
                            $rswrk->Close();
                    } else {
                            $this->fuel->ViewValue = $this->fuel->CurrentValue;
                    }
            } else {
                    $this->fuel->ViewValue = NULL;
            }
            $this->fuel->CssStyle = "";
            $this->fuel->CssClass = "";
            $this->fuel->ViewCustomAttributes = "";

            // rent_type
            if (strval($this->rent_type->CurrentValue) <> "") {
                    switch ($this->rent_type->CurrentValue) {
                            case "0":
                                    $this->rent_type->ViewValue = "Long term leasing";
                                    break;
                            case "1":
                                    $this->rent_type->ViewValue = "Short term leasing";
                                    break;
                            case "2":
                                    $this->rent_type->ViewValue = "Tour Package";
                                    break;
                            default:
                                    $this->rent_type->ViewValue = $this->rent_type->CurrentValue;
                    }
            } else {
                    $this->rent_type->ViewValue = NULL;
            }
            $this->rent_type->CssStyle = "";
            $this->rent_type->CssClass = "";
            $this->rent_type->ViewCustomAttributes = "";

            // vehicle_type_id
            if (strval($this->vehicle_type_id->CurrentValue) <> "") {
                    switch ($this->vehicle_type_id->CurrentValue) {
                            case "0":
                                    $this->vehicle_type_id->ViewValue = "Buy";
                                    break;
                            case "1":
                                    $this->vehicle_type_id->ViewValue = "Sale";
                                    break;
                            case "2":
                                    $this->vehicle_type_id->ViewValue = "Rent";
                                    break;
                            default:
                                    $this->vehicle_type_id->ViewValue = $this->vehicle_type_id->CurrentValue;
                    }
            } else {
                    $this->vehicle_type_id->ViewValue = NULL;
            }
            $this->vehicle_type_id->CssStyle = "";
            $this->vehicle_type_id->CssClass = "";
            $this->vehicle_type_id->ViewCustomAttributes = "";

            // model_id
            if (strval($this->model_id->CurrentValue) <> "") {
                $sFilterWrk = "id = " . ew_AdjustSql($this->model_id->CurrentValue) . "";
            $sSqlWrk = "SELECT `name` FROM `psacar_model`";
            $sWhereWrk = "";
            if ($sFilterWrk <> "") {
                    if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
                    $sWhereWrk .= "(" . $sFilterWrk . ")";
            }
            if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
                    $rswrk = $conn->Execute($sSqlWrk);
                    if ($rswrk && !$rswrk->EOF) { // Lookup values found
                            $this->model_id->ViewValue = $rswrk->fields('name');
                            $rswrk->Close();
                    } else {
                            $this->model_id->ViewValue = $this->model_id->CurrentValue;
                    }
            } else {
                    $this->model_id->ViewValue = NULL;
            }
            $this->model_id->CssStyle = "";
            $this->model_id->CssClass = "";
            $this->model_id->ViewCustomAttributes = "";

            // id
            $this->id->HrefValue = "";
            $this->id->TooltipValue = "";

            // dealer_id
            $this->dealer_id->HrefValue = "";
            $this->dealer_id->TooltipValue = "";

            // model_id
            $this->model_id->HrefValue = "";
            $this->model_id->TooltipValue = "";

            // type_id
            $this->type_id->HrefValue = "";
            $this->type_id->TooltipValue = "";

            // category_id
            $this->category_id->HrefValue = "";
            $this->category_id->TooltipValue = "";

            // price
            $this->price->HrefValue = "";
            $this->price->TooltipValue = "";

            // quality
            $this->quality->HrefValue = "";
            $this->quality->TooltipValue = "";

            // fuel
            $this->fuel->HrefValue = "";
            $this->fuel->TooltipValue = "";

            // rent_type
            $this->rent_type->HrefValue = "";
            $this->rent_type->TooltipValue = "";

            // vehicle_type_id
            $this->vehicle_type_id->HrefValue = "";
            $this->vehicle_type_id->TooltipValue = "";

            // model_id
            $this->model_id->HrefValue = "";
            $this->model_id->TooltipValue = "";

            // year
            $this->year->HrefValue = "";
            $this->year->TooltipValue = "";                

            // Call Row Rendered event
            $this->Row_Rendered();
	}

	// Aggregate list row values
	function AggregateListRowValues() {
	}

	// Aggregate list row (for rendering)
	function AggregateListRow() {
	}

	// Row styles
	function RowStyles() {
            $sAtt = "";
            $sStyle = trim($this->CssStyle);
            if (@$this->RowAttrs["style"] <> "")
                    $sStyle .= " " . $this->RowAttrs["style"];
            $sClass = trim($this->CssClass);
            if (@$this->RowAttrs["class"] <> "")
                    $sClass .= " " . $this->RowAttrs["class"];
            if (trim($sStyle) <> "")
                    $sAtt .= " style=\"" . trim($sStyle) . "\"";
            if (trim($sClass) <> "")
                    $sAtt .= " class=\"" . trim($sClass) . "\"";
            return $sAtt;
	}

	// Row attributes
	function RowAttributes() {
            $sAtt = $this->RowStyles();
            if ($this->Export == "") {
                    foreach ($this->RowAttrs as $k => $v) {
                            if ($k <> "class" && $k <> "style" && trim($v) <> "")
                                    $sAtt .= " " . $k . "=\"" . trim($v) . "\"";
                    }
            }
            return $sAtt;
	}

	// Field object by name
	function fields($fldname) {
            return $this->fields[$fldname];
	}

	// Table level events
	// Recordset Selecting event
	function Recordset_Selecting(&$filter) {

            // Enter your code here	
	}

	// Recordset Selected event
	function Recordset_Selected(&$rs) {

            //echo "Recordset Selected";
	}

	// Recordset Search Validated event
	function Recordset_SearchValidated() {

            // Example:
            //global $MyTable;
            //$MyTable->MyField1->AdvancedSearch->SearchValue = "your search criteria"; // Search value

	}

	// Recordset Searching event
	function Recordset_Searching(&$filter) {

            // Enter your code here	
	}

	// Row_Selecting event
	function Row_Selecting(&$filter) {

            // Enter your code here	
	}

	// Row Selected event
	function Row_Selected(&$rs) {

            //echo "Row Selected";
	}

	// Row Rendering event
	function Row_Rendering() {

            // Enter your code here	
	}

	// Row Rendered event
	function Row_Rendered() {

            // To view properties of field class, use:
            //var_dump($this-><FieldName>); 

	}

	// Row Inserting event
	function Row_Inserting(&$rs) {

            // Enter your code here
            // To cancel, set return value to FALSE

            return TRUE;
	}

	// Row Inserted event
	function Row_Inserted(&$rs) {
            //echo "Row Inserted"                               
	}

	// Row Updating event
	function Row_Updating(&$rsold, &$rsnew) {

		// Enter your code here
		// To cancel, set return value to FALSE

		return TRUE;
	}

	// Row Updated event
	function Row_Updated(&$rsold, &$rsnew) {

		//echo "Row Updated";
	}

	// Row Update Conflict event
	function Row_UpdateConflict(&$rsold, &$rsnew) {

		// Enter your code here
		// To ignore conflict, set return value to FALSE

		return TRUE;
	}

	// Row Deleting event
	function Row_Deleting(&$rs) {

		// Enter your code here
		// To cancel, set return value to False

		return TRUE;
	}

	// Row Deleted event
	function Row_Deleted(&$rs) {

		//echo "Row Deleted";
	}

	// Email Sending event
	function Email_Sending(&$Email, &$Args) {

		//var_dump($Email); var_dump($Args); exit();
		return TRUE;
	}
}
?>
